﻿package com.sohu.sns.avatar {
	import flash.display.BitmapData;
	import flash.display.Loader;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.IOErrorEvent;
	import flash.net.URLRequest;
	import flash.system.LoaderContext;

	public class PhotoLoader extends Sprite implements IEditSource {
		private var path : String;
		private var loader : Loader;
		private var bitmapData : BitmapData;
		public static var COMPLETE : String = "complete";

		public function PhotoLoader(param1 : String) {
			this.path = param1;
			return;
		}

		
		public function getEditSource() : void {
			this.loader = new Loader();
			this.loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoadComp);
			this.loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, onIOError);
			this.loader.load(new URLRequest(this.path), new LoaderContext(true));
			return;
		}

		
		private function onIOError(event : IOErrorEvent) : void {
			return;
		}

		
		public function get editData() : BitmapData {
			return this.bitmapData;
		}

		
		private function onLoadComp(event : Event) : void {
			this.bitmapData = new BitmapData(event.target['content']['width'], event.target['content']['height']);
			this.bitmapData.draw(event.target['content'], null, null, null, null, true);
			this.dispatchEvent(new Event(COMPLETE));
			return;
		}
		
	}
}
